package com.nervenets.web.hibernate.domain.user;

import com.nervenets.web.enumeration.Gender;
import com.nervenets.web.hibernate.DomainObject;
import com.nervenets.web.hibernate.domain.Manager;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Type;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

/**
 * 用户
 */
@EqualsAndHashCode(callSuper = true)
@Entity
@Table(name = "users", indexes = {
        @javax.persistence.Index(name = "_idx_user_open_id", columnList = "openId"),
        @javax.persistence.Index(name = "_idx_user_union_id", columnList = "unionId")
})
@Data
@NoArgsConstructor
@AllArgsConstructor
public class User extends DomainObject {
    private String openId;
    private String unionId;
    private Gender gender = Gender.female;
    private String mobile;
    private String password;
    private boolean enable = true;
    private int lastLoginTime;
    private long inviteUserId;
    @Type(type = "com.nervenets.web.adapter.jsonType.UserExtraJson")
    @Column(columnDefinition = "text")
    private UserExtra extra = new UserExtra();
    private int updateTime;

    @ManyToMany
    @JoinTable(
            name = "team_of_user",
            joinColumns = {@JoinColumn(name = "user_id", referencedColumnName = "id")},
            inverseJoinColumns = {@JoinColumn(name = "manager_id", referencedColumnName = "id")}
    )
    private Set<Manager> teams = new HashSet<>();
}
